package com.artisan.admin.controllers;

import com.artisan.admin.resultModels.MessageBase;
import com.artisan.admin.resultModels.adResultModels.AdResultModel;
import com.artisan.admin.resultModels.adTypeResultModels.AdTypeResultModel;
import com.artisan.domain.dto.AdDto;
import com.artisan.domain.dto.AdTypeDto;
import com.artisan.domain.dto.PageDto;
import com.artisan.domain.serviceInterface.IAdService;
import com.artisan.domain.serviceInterface.IAdTypeService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 广告类型控制器
 */
@RequestMapping("/api/adType")
@RestController
@Api("广告类型模块")
@ApiOperation(value = "广告类型模块")
public class AdTypeController {
    private final IAdTypeService adTypeService;

    public AdTypeController(IAdTypeService adTypeService) {
        this.adTypeService = adTypeService;
    }
    /**
     * 获得广告类型列表
     * @param status 状态
     */
    // GET /list
    @ApiOperation(value = "获得广告类型列表")
    @ApiImplicitParams(
            @ApiImplicitParam(paramType = "query", name = "status", dataType = "Int", required = true, value = "状态", defaultValue = "1")
    )
    @ApiResponses(@ApiResponse(code = 200, response = AdTypeResultModel.class, message = "成功"))
    @RequestMapping(value ={"/list"}, method = {RequestMethod.GET})
    public MessageBase getList(@RequestParam(value = "status")int status) {
        MessageBase result = new MessageBase();
        List<AdTypeDto> dtos = this.adTypeService.findList(status);

        ArrayList<AdTypeResultModel> models  = new ArrayList<>();

        dtos.forEach(dto -> {
            AdTypeResultModel model = new AdTypeResultModel();
            model.setId(dto.getId());
            model.setName(dto.getName());

            models.add(model);
        });

        result.setData(models);
        return result;
    }

}
